var t = getApp();

Page({
    data: {
        hot: [],
        category: [],
        acindex: 0,
        tabsHeight: "",
        topHeight: "",
        currBox: "tab0",
        heightArray: [],
        toview: "ind0"
    },
    onLoad: function(t) {
        this.getdata();
    },
    goDetail: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.name;
        wx.navigateTo({
            url: "/packageH/cpsList/cpsList?id=" + "".concat(a, "&name=").concat(e)
        });
    },
    taptest: function(t) {
        var a = t.currentTarget.dataset.ind;
        this.setData({
            acindex: a
        }), this.setData({
            toview: "ind".concat(a)
        });
    },
    tabScroll: function(t) {},
    bincroll: function(t) {
        var a = t.detail.scrollTop;
        a <= this.data.topHeight && this.data.curr ? this.setData({
            curr: !1
        }) : a > this.data.topHeight && !this.data.curr && this.setData({
            curr: !0
        });
        for (var e = 0; e < this.data.category.length; e++) if (this.data.heightArray[1] >= t.detail.scrollTop) this.setData({
            acindex: 0,
            currBox: "tab0"
        }); else {
            if (this.data.heightArray[e] < t.detail.scrollTop + 50 && t.detail.scrollTop + 50 < this.data.heightArray[e + 1]) {
                this.setData({
                    acindex: e,
                    currBox: "tab" + e
                });
                break;
            }
            this.data.heightArray[this.data.category.length - 1] <= t.detail.scrollTop + 50 && this.setData({
                acindex: this.data.category.length - 1,
                currBox: "tab" + this.data.category.length - 1
            });
        }
    },
    testTabs: function() {
        for (var t = this, a = [], e = function(e) {
            wx.createSelectorQuery().select("#ind".concat(e)).boundingClientRect(function(o) {
                a.push(o.top - t.data.topHeight - 100), e == t.data.category.length - 1 && t.setData({
                    heightArray: a
                });
            }).exec();
        }, o = 0; o < this.data.category.length; o++) e(o);
    },
    onReady: function() {
        var t = this;
        wx.createSelectorQuery().select(".page-section-spacing").boundingClientRect(function(a) {
            console.log(a), t.setData({
                tabsHeight: a.top
            });
        }).exec();
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getdata: function() {
        wx.showLoading({
            title: "加载中"
        });
        var a = this, e = t.getNetAddresss("plugin.aggregation-cps.api.equity");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                wx.hideLoading(), 1 == e.result ? (a.setData({
                    hot: e.data.hot,
                    category: e.data.category,
                    brand: e.data.category[0].brand
                }), setTimeout(function() {
                    wx.createSelectorQuery().select(".top").boundingClientRect(function(t) {
                        a.setData({
                            topHeight: t.height
                        });
                    }).exec(), a.testTabs();
                }, 200)) : wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    }
});